import {
	MessageConstant
} from "zpub_http/constant/MessageConstant.js"
import {
	WhatConstant
} from "zpub_http/constant/WhatConstant.js"
import {
	HttpParamKeyValue
} from "zpub_svr/constant/HttpParamKeyValue.js"
import {
	HttpProtocol
} from "zpub_http/http/HttpProtocol.js"
import {
	BaseService
} from "zpub_http/service/BaseService.js"
import {
	MajorMinorBusiness
} from "../../constant/MajorMinorBusiness.js"
import {
	FldValueBusiness
} from "../../constant/FldValueBusiness.js"
import {
	MajorMinorConstant
} from "zpub_db/constant/MajorMinorConstant.js"
import {
	JsonUtil
} from 'zpub_bas/util/JsonUtil.js'
import {
	UserMethod
} from "zpub_db/method/UserMethod.js"
import {
	DateUtil
} from "../../util/DateUtil.js"



/*
 * 功能：公共服务模块
 * 需要传入的键：
 * 传入的值类型：
 * 传入的值含义：
 * 是否必传 ：
 * 作者：郑朝军 on 2019/4/7 23:23
 * 邮箱：1250393285@qq.com
 * 公司：武汉智博创享科技有限公司
 */
class OrderService extends BaseService {

	/*
	 * 查询商品<br/>
	 */
	static queryOrderInfo(page, listener) {
		listener.showLoading({
			title: '正在查询商品'
		});
		let json = [{
			"_major": "97",
			"_minor": "4",
			"as": "a",
			"cols": "time,price as sfprice,state,color as sfcolor,size as sfsize,nums",
			"types": "i"
		}, {
			"_major": "97",
			"_minor": "2",
			"as": "b",
			"cols": "*",
			"types": "i"
		}]
		let protocol = new HttpProtocol();
		protocol
			.setService('SvrPubQueryMultiTableControl')
			.setMethod('queryMultiTableUnion')
			// .addParam('exp', " a.userid =" + UserMethod.getUser().name + " AND state = " + 0)
			.addParam('exp', "a.shopid = b.id AND a.userid =1")
			.addParam('json', JsonUtil.jsonToString(json))
			.addParam('pageno', 1)
			.addParam('pagesize', 15)
			.post().then((data) => {
				let jo = this.responseData(data);
				if (this.isDataInvalid("queryOrderInfo", jo, listener)) {
					return MessageConstant.MSG_EMPTY;
				}
				console.log(jo);
				// [shopGroup=团购]
				// [categoryList=分类精选]
				// [bgList=背景精选择]
				// [bgList2=背景精选择]
				// [loveList=猜你喜欢]
				let map = {
					orderQBList: [],
					orderDFKList: [],
					orderDSHList: [],
					orderDPJList: [],
					orderSHList: [],
				};
				data.result.list.forEach((item, index, array) => {
					if (item.state == 1) {
						map.orderQBList.push({
							time: DateUtil.dataFormatsFull(item['time']),
							state: item['state'],
							price: item['sfprice'],
							nums: item['nums'],
							goodsList: [item]
						});
					} else if (item.state == 2) {
						map.orderDFKList.push(item);
					} else if (item.state == 3) {
						map.orderDSHList.push(item);
					} else if (item.state == 4) {
						map.orderDPJList.push(item);
					} else if (item.state == 5) {
						map.orderSHList.push(item);
					}
				});

				this.sendMessage("queryOrderInfo", map, WhatConstant.WHAT_NET_DATA_SUCCESS, listener);
			})
			.catch((err) => {
				this.sendMessage("queryOrderInfo", err, WhatConstant.WHAT_NET_DATA_FAIL, listener);
			});
	}
}

export {
	OrderService
}
